//
//  GLRecordFooterCell.m
//  KTools
//
//  Created by zhiyong.kuang on 2017/10/25.
//  Copyright © 2017年 zhiyong.kuang. All rights reserved.
//

#import "GLFormRecordFooterCell.h"
#import <Masonry/Masonry.h>
@interface GLFormRecordFooterCell()
@property(nonatomic,assign)BOOL isExpand;
@property(nonatomic,strong)UIImageView* imgV;
@property(nonatomic,strong)UIButton* btn;
@property(nonatomic,strong)UIImageView* refundImageV;

@end


@implementation GLFormRecordFooterCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self =[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    UIImageView *leftLineImageView = [[UIImageView alloc] init];
    leftLineImageView.backgroundColor = [UIColor colorWithRed:228.0/255.0 green:228.0/255.0 blue:228.0/255.0 alpha:1];
    [self.contentView addSubview:leftLineImageView];
    
    UIImageView *leftImageView = [[UIImageView alloc] init];
    leftImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(historyRecordBtnClick)];
    [leftImageView addGestureRecognizer:tap];
    leftImageView.image = [UIImage imageNamed:@"icon-down2"];
    leftImageView.highlightedImage = [UIImage imageNamed:@"ic_check_up"];
    [self.contentView addSubview:leftImageView];
    self.imgV = leftImageView;
    
    UIButton *historyRecordBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [historyRecordBtn setTitle:@"历史跟踪记录" forState:UIControlStateNormal];
    [historyRecordBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    historyRecordBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];

    [historyRecordBtn addTarget:self action:@selector(historyRecordBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:historyRecordBtn];
    self.btn = historyRecordBtn;
    
    UIImageView *refundImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon-tui"]];
    refundImageV.hidden = true;
    self.refundImageV = refundImageV;
    [self.contentView addSubview:refundImageV];
    
    [self.refundImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.contentView);
        make.right.equalTo(self.contentView);
    }];
    
    [leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(15);
        make.left.mas_equalTo(self.contentView).offset(self.edgeMargin);
        make.centerY.equalTo(self.contentView);
    }];
    
    [leftLineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.contentView);
        make.width.mas_equalTo(1.0/[UIScreen mainScreen].scale);
        make.centerX.equalTo(leftImageView.mas_centerX);
    }];
    
    [historyRecordBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@20);
        make.centerY.equalTo(leftImageView);
        make.left.equalTo(leftImageView.mas_right).offset(10);
    }];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}



- (void)historyRecordBtnClick
{
    self.isExpand = !self.isExpand;
    [self valueDidChanged:[NSNumber numberWithBool:self.isExpand]];
    [self clicked:nil subTag:@"footerCell"];
    
}

-(void)setRowValue:(id)value{
    [super setRowValue:value];
    self.isExpand = [value boolValue];
}
/*
 *need call
 */

-(void)setIsExpand:(BOOL)isExpand{
    _isExpand = isExpand;
    self.imgV.highlighted = _isExpand;
    self.btn.selected = _isExpand;
}

-(void)setRefundImageHidden:(BOOL)refundImageHidden{
    _refundImageHidden = refundImageHidden;
    self.refundImageV.hidden = _refundImageHidden;
}

@end
